package com.bloom.spider.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bloom.common.annotation.Log;
import com.bloom.common.core.controller.BaseController;
import com.bloom.common.core.domain.AjaxResult;
import com.bloom.common.enums.BusinessType;
import com.bloom.spider.domain.SpiderField;
import com.bloom.spider.service.ISpiderFieldService;
import com.bloom.common.utils.poi.ExcelUtil;
import com.bloom.common.core.page.TableDataInfo;

/**
 * 配置字段Controller
 * 
 * @author bloom
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/spider/spiderField")
public class SpiderFieldController extends BaseController
{
    @Autowired
    private ISpiderFieldService spiderFieldService;

    /**
     * 查询配置字段列表
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpiderField spiderField)
    {
        startPage();
        List<SpiderField> list = spiderFieldService.selectSpiderFieldList(spiderField);
        return getDataTable(list);
    }

    /**
     * 导出配置字段列表
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:export')")
    @Log(title = "配置字段", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpiderField spiderField)
    {
        List<SpiderField> list = spiderFieldService.selectSpiderFieldList(spiderField);
        ExcelUtil<SpiderField> util = new ExcelUtil<SpiderField>(SpiderField.class);
        return util.exportExcel(list, "配置字段数据");
    }

    /**
     * 获取配置字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return AjaxResult.success(spiderFieldService.selectSpiderFieldById(fieldId));
    }

    /**
     * 新增配置字段
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:add')")
    @Log(title = "配置字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpiderField spiderField)
    {
        return toAjax(spiderFieldService.insertSpiderField(spiderField));
    }

    /**
     * 修改配置字段
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:edit')")
    @Log(title = "配置字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpiderField spiderField)
    {
        return toAjax(spiderFieldService.updateSpiderField(spiderField));
    }

    /**
     * 删除配置字段
     */
    @PreAuthorize("@ss.hasPermi('spider:spiderField:remove')")
    @Log(title = "配置字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(spiderFieldService.deleteSpiderFieldByIds(fieldIds));
    }
}
